#include <iostream>
using namespace std;

class Base
{
public:
	virtual void Func1() //虚函数
	{
		cout << "Base::Func1()" << endl;
	}
	virtual void Func2()
	{
		cout << "Base::Func2()" << endl;
	}
	void Func3()  //不是虚函数
	{
		cout << "Base::Func3()" << endl;
	}
private:
	int _b = 1;
};

class Derive : public Base
{
public:
	virtual void Func1()
	{
		cout << "Derive::Func1()" << endl;
	}
private:
	int _d = 2;
};


void Test1()
{
	const char* str = "1111111";
	cout << str << endl;
	printf("%p\n", &str);
	printf("%p\n", &Base::Func1);
	printf("%p\n", &Base::Func2);
	printf("%p\n", &Base::Func3);

}


void Func1(Base * p) //动态绑定
{
	p->Func1();//运行时绑定/动态绑定
	p->Func3(); //编译时绑定/静态绑定
}
void Test2()
{
	Func1(new Base); 
	Func1(new Derive);
}


void Test3()
{
	int i = 1;
	static int j = 2;
	int* p1 = new int; //p仍然在栈上，但是p的地址在堆上
	const char* p2 = "xxxxx";

	printf("栈：%p\n", &i);
	printf("静态区：%p\n", &j);
	printf("堆：%p\n", p1);
	printf("常量区：%p\n", p2);

	Base b;
	Derive d;

	//支持类型转换
	//int/double/char
	// int 和 int* 指针之间
	printf("Base虚表地址：%p\n", *((int*)&b));
	printf("Derive虚表地址：%p\n", *((int*)&d));
	printf("Base虚表地址：%p\n", &b);
	printf("Derive虚表地址：%p\n", &d);

	////同一个类型地址相同
	//Base b1;
	//Base b2;
}

//静态多态：函数模板、重载
//动态多态：

int main()
{
	//Test1();
	//Test2();

	Test3();


	return 0;
}